import { finance } from "../../../../js/modules/store.js";
import { theme } from "../../../../js/modules/theme.js";
import { util } from '../../../../js/util';
import authorize from '../../../../js/modules/authorize.js'
import BasePage from '../../../../js/common/base-page'
import {
  wholesaleSettings
} from "../../../../js/modules/gloab";
BasePage({
  pageKey: "rechargeDetail",

  /**
   * 页面的初始数据
   */
  data: {
    decimalDigits: 2,//金额小数位数
    integral: 0,
    page: {
      PageIndex: 1,
      PageSize: 20,
    },
    list: [],
    hasMoreData: true,
  },

  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {
    var that = this;
    this.getWholesaleConfig();
    that.loadList();
  },

  /**加载列表 */
  loadList() {
    var that = this;
    var page = this.data.page;
    finance.get_prestore_detail(page, function (content) {
      var hasMoreData = content.count > (page.PageIndex) * page.PageSize;
      var index = that.data.list.length;
      var data = content.data;
      //当分页大于1时，累加
      if (page.PageIndex > 1) {
        data = that.data.list.concat(data);
      }
      //如果key为变量作为key值的时候要用[]包裹起来
      that.setData({
        list: data,
        hasMoreData: hasMoreData
      });
    })
  },
  /**
* 页面相关事件处理函数--监听用户下拉动作
*/
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    this.data.page.PageIndex = 1;
    this.loadList();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function (e) {
    wx.stopPullDownRefresh();
    if (this.data.hasMoreData) {
      var index = this.data.page.PageIndex;
      this.data.page.PageIndex = index + 1;
      this.loadList();
    }
  },
  /**加载配置项参数 */
  getWholesaleConfig() {
    let that = this;
    let config = wholesaleSettings.getConfig();
    that.setData({
      quantityDigits: config.quantityDigits,
      priceDigits: config.priceDigits,
      freightMode: config.freightMode,
      openComment: config.openComment,
      decimalDigits: config.decimalDigits
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {


  },


  onSkipTo(e) {
    let idx = e.currentTarget.dataset.idx;
    let current = this.data.list[idx];
    if (current == undefined) return;
    if (current.OddNumber && current.OddNumber.length > 0) {
      theme.routerTo("orderDetail", {
        oddNumber: current.OddNumber
      });
    }

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  onUnload: function (e) {
    this.data.pre_page = this.getPreData();
    this.data.pre_page.data.isBack = true;
  },
  getPreData: function () {
    const pages = getCurrentPages();
    const length = pages.length;
    const prePage = pages[length - 2]; //上一页
    return prePage;
  }
})